{include file="public/head"/}
<div class="layui-fluid" id="LAY-app-message">
    <div class="layui-card">
        <div class="layui-card-header">分类管理</div>
        <div class="layui-card-body">
            <div class="clt-auth-btns" style="margin-bottom: 10px;">
                <button class="layui-btn layui-btn-sm" data-type="add"><i class="layui-icon layui-icon-add-1"></i>添加分类</button>
            </div>
            <table class="layui-table" id="list" lay-filter="list"></table>
        </div>
    </div>
</div>
{include file="public/foot"/}
<script type="text/html" id="title">
	{{d.category_name}}
</script>
<script type="text/html" id="lvl">
	{{d.lvl}} 级
</script>
<script type="text/html" id="status">
    <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="status" {{ d.status == 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="action">
	{{# if(d.is_page==1){ }}
	<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="page_edit">内容</a>
	{{# } }}
	<a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
</script>
<script type="text/html" id="set">
	<a class="layui-btn layui-btn-primary layui-btn-xs"
		{{# if(d.lvl==1){ }}
	   	lay-event="detail"
		{{# } }}
	>
		{{# if(d.lvl==1){ }}
			<i class="layui-icon layui-icon-search"></i>查看下级
		{{#
		}else { }}
			<i class="layui-icon ">无下级</i>
		{{# } }}
	</a>
	<a class="layui-btn layui-btn-primary layui-btn-xs"
	   {{# if(d.lvl==1){ }}
	   lay-event="doadd"
	   {{# } }}
	>
		{{# if(d.lvl==1){ }}
		<i class="layui-icon layui-icon-add-1"></i>添加下级
		{{#
		}else { }}
		<i class="layui-icon ">无操作</i>
		{{# } }}
	</a>
</script>
<script>
    layui.config({
        base: '__LAYDMIN__/',{if config('app.app_debug')}version: true{/if}
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','admin', 'table', 'util','upload'],function(){
		var $ = layui.$, admin = layui.admin, table = layui.table, element = layui.element, form = layui.form,util = layui.util, upload = layui.upload;
		var tableLoadDiv = window.top.layer.load(0,{shade:[0.15, '#000']}); //加载层,table.render完成时需要关闭
		//全部数据
		tableIn = table.render({
			elem: '#list',
			url: '{:url(SYS_PATH.'/'.CONTROLLER.'/category')}',
			method: 'post',
			cols: [[
				{field: 'category_id', title: 'ID', width: 80, fixed: true},
				{field: 'create_name', title: '栏目名称',align: 'center', width: 250,templet: '#title'},
				{field: 'sort', title: '排序',align: 'center', width: 250},

				{field: 'create_time', title: '创建时间',align: 'center', width: 200,templet: function(d){
					return util.toDateString(d.create_time*1000,'yyyy-MM-dd HH:mm:ss');
				}},
				{field: 'update_time', title: '修改时间',align: 'center', width: 200,templet: function(d){
					return util.toDateString(d.update_time*1000,'yyyy-MM-dd HH:mm:ss');
				}},

				{width: 150, title:'操作',align: 'center', toolbar: '#action'}
			]],
			done:function (res) {   //返回数据执行回调函数
			    	window.top.layer.close(tableLoadDiv);    //返回数据关闭loading
			}				
		});
		
		$('.clt-auth-btns .layui-btn').on('click', function () {
			var type = $(this).data('type');
			layui.layerOpen("{:url(SYS_PATH.'/'.CONTROLLER.'/categoryAdd')}");
		});		
		
		
		table.on('edit(list)', function(obj){
			var value = obj.value //得到修改后的值
				,field = obj.field; //得到字段
			admin.req({
				url: '{:url(SYS_PATH.'/'.CONTROLLER.'/categoryListEdit')}?id='+obj.data.id+'&'+field+'='+value
				, success: function (res) {
					if(res.code==0){
						window.top.layer.msg(res.msg,{time:1000,icon:1,shade:[0.5,'#000']});
					}
					tableIn.reload();
				}
			});
		});		
		
		
		
	   //监听工具条
		table.on('tool(list)', function (obj) {
			var data = obj.data;
			var id = data.category_id;
			if (obj.event === 'del') {
				var uri="{:url(SYS_PATH.'/'.CONTROLLER.'/categoryDelete')}"
				layui.doDelete(uri,"确定要删除吗？",id,obj);//单个删除接口
			}else if (obj.event === 'edit') {
				layui.layerOpen("{:url(SYS_PATH.'/'.CONTROLLER.'/categoryEdit')}?id="+id);
			} else if (obj.event === 'detail') {
				layui.layerOpen("{:url(SYS_PATH.'/'.CONTROLLER.'/category')}?pid="+id);
			}else if (obj.event === 'doadd') {
				layui.layerOpen("{:url(SYS_PATH.'/'.CONTROLLER.'/categoryAdd')}?pid="+id);
			}
		});		

	});
</script>
</body>
</html>